package model.kml;

import java.util.ArrayList;
import java.util.List;

import util.StringUtils;

public class Document {
	
	private String name;
	private Boolean open = true;
	private List<Style> styles;
	private List<Placemark> places;
	
	public Document(){
		this.places = new ArrayList<Placemark>();
		this.styles = new ArrayList<Style>();
	}
	
	public void addPlacemark(Placemark place){
		this.places.add(place);
	}
	
	public void addStyle(Style style){
		this.styles.add(style);
	}
	
	public List<Placemark> getPlacemarks(){
		return this.places;
	}
	
	public List<Style> getStyles(){
		return this.styles;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Boolean getOpen() {
		return open;
	}

	public void setOpen(Boolean open) {
		this.open = open;
	}

	public List<Placemark> getPlaces() {
		return places;
	}

	public void setPlaces(List<Placemark> places) {
		this.places = places;
	}
	
	@Override
	public String toString(){
		String docString = "<Document>\n";
		if(!StringUtils.isNullOrEmpty(this.name)) 
			docString += "<name><![CDATA["+this.name+"]]></name>\n";
		docString += "<open>1</open>\n";
		for (Style style : this.styles) {
			docString += style.toString();
		}
		for (Placemark place : this.places) {
			docString += place.toString();
		}
		docString +="</Document>\n";
		return docString;
	}
}
